# query <- getbb("Leuven, Belgium") %>%
# opq() %>%
# add_osm_feature("highway") %>%
# osmdata_sf()
#
# glimpse(query)
#
# leuvenHighways <- query$osm_lines
#
# glimpse((leuvenHighways))
##save
# saveRDS(leuvenHighways,
# here::here('data/rawData/leuvenHighways.rds'))
leuvenHighways <- readRDS(here::here('data/rawData/leuvenHighways.rds'))
leuvenHighwayFilter <- leuvenHighways %>%
select(osm_id, geometry)
leuvenHighwayFilter %>%
tm_shape()+
tm_lines()
leuvenHighwayFilter <- leuvenHighways %>%
select(osm_id, highway, geometry)
# query <- getbb("Leuven, Belgium") %>%
# opq() %>%
# add_osm_feature("name", 'Sint-Pieterskerk') %>%
# osmdata_sf()
#
# glimpse(query)
#
# mapCenter <- query$osm_polygons
#
# glimpse((leuvenHighways))
#saveRDS(mapCenter,
# here::here('data/rawData/mapCenter.rds'))
mapCenter <- readRDS(here::here('data/rawData/mapCenter.rds'))
mapBuffer <- mapCenter %>%
st_transform(3857) %>%
summarise(geometry = st_union(geometry)) %>%
st_centroid() %>%
st_buffer(500) %>%
st_as_sf()
glimpse(mapBuffer)
## Rows: 1
## Columns: 1
## $ geometry <POLYGON [m]> POLYGON ((523837.9 6600010,...
tm_shape(mapBuffer)+
tm_borders(lwd =2, lty='dashed')+
tm_dots()+
tm_fill(col ='red')
##chose a roads
mapRoads <- leuvenHighwayFilter %>%
st_transform(3857) %>%
st_intersection(mapBuffer)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
glimpse(mapRoads)
## Rows: 385
## Columns: 3
## $ osm_id <chr> "3343955", "3616406", "3616407", "3869834", "3877007", "39916~
## $ highway <chr> "pedestrian", "residential", "service", "residential", "resid~
## $ geometry <LINESTRING [m]> LINESTRING (523518.5 659989..., LINESTRING (523284~
tm_shape(mapRoads)+
tm_lines(col='highway')+
tm_shape(mapBuffer)+
tm_borders(lwd=3.5)
mapRoadsSP <- as(mapRoads, 'Spatial') %>%
as.data.frame()
glimpse(mapRoadsSP)
## Rows: 385
## Columns: 2
## $ osm_id <chr> "3343955", "3616406", "3616407", "3869834", "3877007", "399163~
## $ highway <chr> "pedestrian", "residential", "service", "residential", "reside~